// 商品详情页的顶部导航
<template>
  <div class="details-nav-bar">
    <TitleBar @clickLeft="back">
      <div slot="left">
        <img src="~assets/img/common/back.svg" />
      </div>
      <div slot="center" class="details-nav-center">
        <div
          v-for="(item,index) in titles"
          :key="index"
          class="item-nav"
          :class="{'active':currIndex == index }"
          @click="navItemClick(index)"
        >{{item}}</div>
      </div>
    </TitleBar>
  </div>
</template>
<script>
import TitleBar from "components/common/titlebar/TitleBar";
export default {
  data() {
    return {
      titles: ["商品", "参数", "评论", "推荐"]
    };
  },

  methods: {
    //导航切换的点击事件
    navItemClick(index) {
      if (this.currIndex != index) {
        this.$emit("navBarClick", index);
      }
    },
    //返回
    back() {
      this.$router.go(-1);
    }
  },
  computed: {},
  props: {
    currIndex: {
      type: Number,
      default: 0
    }
  },
  components: {
    TitleBar
  }
};
</script>
<style lang="scss" scoped>
.details-nav-center {
  display: flex;
  font-size: 14px;
  text-align: center;
  .item-nav {
    flex: 1;
  }
}
.active {
  color: var(--color-high-text);
}
</style>